package com.company.service.impl;

import com.company.entity.user;
import com.company.service.StartService;
import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;

import javax.naming.Name;
import java.util.List;
import java.util.Scanner;

public class Zhuce implements StartService {
    Scanner sc=new Scanner(System.in);

    @Override
    public List ex(List list) {
        Logdengluplus l=new Logdengluplus();
        Logdengluplus lo1= new Logdengluplus();
        System.out.println("-----注册-----");
        System.out.println("输入您的名字：");
        String name=sc.next();
        lo1.setName(name);
        for (; ; ) {
            System.out.println("输入密码：：");
            String pwd;
            boolean flag = true;
            do {
                pwd = sc.next();
                if (pwd.length() < 6) {
                    System.out.println("密码不能小于6位");
                    flag = false;
                } else {
                    flag = true;
                    System.out.println("再次输入密码：");
                    String zc=sc.next();

                    if (!zc.equals(pwd)){
                        System.out.println("两次输入密码不正确！");
                    }else {
                        l.setMima(pwd);
                        l.setName(name);
                        int iret=panduan(name,list);
                        if (iret==0){
                            System.out.println("注册成功了");
                            System.out.println("--------------------");
                            list.add(l);
                        }else{
                            System.out.println("用户已注册");
                        }
                        return list;

                    }
                }
            } while (!flag);
            break;
        }
        return null;
    }
    public int panduan(String name,List list){
        for (int i = 0; i < list.size(); i++) {
            Logdengluplus l=(Logdengluplus)list.get(i);
            if(name.equals(l.getName())){
                return 1;
            }
        }
        return 0;
    }
    }

